﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.OracleClient;
using System.Collections.Generic;
/// <summary>
///LineDAOs 的摘要说明
/// </summary>
public class LineDAOs
{
    private static LineDAOs instance = null;
	public LineDAOs()
	{

	}
    public List<String> getLineNameList()
    {
        String connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["OracleConnectionString"].ConnectionString;
        OracleConnection conn = new OracleConnection(connectionString);
        OracleCommand cmd = new OracleCommand();
        cmd.Connection = conn;
        cmd.CommandText = "Select distinct TRANSMISSIONLINE from pgms_tower_info";
        conn.Open();
        OracleDataReader dr = cmd.ExecuteReader();
        List<String> nameList = new List<string>();
        if (dr.HasRows)
        {
            while (dr.Read())
            {
                if (!dr.IsDBNull(0))
                    nameList.Add(dr.GetString(0));
            }
        }
        dr.Close();
        conn.Close();
        return nameList;
    }
    public Line getLineByName(String name){
        String connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["OracleConnectionString"].ConnectionString;
        OracleConnection conn = new OracleConnection(connectionString);
        OracleCommand cmd = new OracleCommand();
        cmd.Connection = conn;
        cmd.CommandText = "Select VALUE from (select VALUE from PGMS_CURRENT_INFO t where t.TRANSMISSIONLINE = :lineName and t.NAME='实时电流' order by t.TIME desc) where rownum = 1";
        cmd.Parameters.Add(":lineName", OracleType.VarChar);
        cmd.Parameters[":lineName"].Value = name;
        conn.Open();
        OracleDataReader dr = cmd.ExecuteReader();
        Line line = new Line(name);
        if (dr.HasRows)
        {
            dr.Read();
            if (!dr.IsDBNull(0))
                line.RealtimeCcurrent = dr.GetFloat(0)+"";
        }

        cmd.CommandText = "Select VALUE from (select VALUE from PGMS_CURRENT_INFO t where t.TRANSMISSIONLINE = :lineName and t.NAME='导线温度' order by t.TIME desc) where rownum = 1";
        dr = cmd.ExecuteReader();
        if (dr.HasRows)
        {
            dr.Read();
                if (!dr.IsDBNull(0))
            line.ConductorTemperature = dr.GetFloat(0)+"";
        }

        cmd.CommandText = "Select VALUE from (select VALUE from PGMS_CURRENT_INFO t where t.TRANSMISSIONLINE = :lineName and t.NAME='温度' order by t.TIME desc) where rownum = 1";
        dr = cmd.ExecuteReader();
        if (dr.HasRows)
        {
            dr.Read();
                if (!dr.IsDBNull(0))
            line.EnvironmentTemperature = dr.GetFloat(0)+"";
        }

        cmd.CommandText = "Select VALUE from (select VALUE from PGMS_CURRENT_INFO t where t.TRANSMISSIONLINE = :lineName and t.NAME='在线状态' order by t.TIME desc) where rownum = 1";
        dr = cmd.ExecuteReader();
        if (dr.HasRows)
        {
            dr.Read();
                if (!dr.IsDBNull(0))
            line.OnlineStatus = dr.GetFloat(0)+"";
        }

        cmd.CommandText = "Select VALUE from (select VALUE from PGMS_CURRENT_INFO t where t.TRANSMISSIONLINE = :lineName and t.NAME='实时功率' order by t.TIME desc) where rownum = 1";
        dr = cmd.ExecuteReader();
        if (dr.HasRows)
        {
            dr.Read();
                if (!dr.IsDBNull(0))
            line.RealtimePower = dr.GetFloat(0)+"";
        }

        cmd.CommandText = "Select VALUE from (select VALUE from PGMS_CURRENT_INFO t where t.TRANSMISSIONLINE = :lineName and t.NAME='总功率' order by t.TIME desc) where rownum = 1";
        dr = cmd.ExecuteReader();
        if (dr.HasRows)
        {
            dr.Read();
                if (!dr.IsDBNull(0))
            line.TotalPower = dr.GetFloat(0)+"";
        }

        cmd.CommandText = "Select VALUE from (select VALUE from PGMS_CURRENT_INFO t where t.TRANSMISSIONLINE = :lineName and t.NAME='热稳限额' order by t.TIME desc) where rownum = 1";
        dr = cmd.ExecuteReader();
        if (dr.HasRows)
        {
            dr.Read();
                if (!dr.IsDBNull(0))
            line.ThermalLimit = dr.GetFloat(0)+"";
        }

        cmd.CommandText = "Select VALUE from (select VALUE from PGMS_CURRENT_INFO t where t.TRANSMISSIONLINE = :lineName and t.NAME='功率限额' order by t.TIME desc) where rownum = 1";
        dr = cmd.ExecuteReader();
        if (dr.HasRows)
        {
            dr.Read();
                if (!dr.IsDBNull(0))
            line.PowerLimit = dr.GetFloat(0)+"";
        }

        cmd.CommandText = "Select VALUE from (select VALUE from PGMS_CURRENT_INFO t where t.TRANSMISSIONLINE = :lineName and t.NAME='综合告警' order by t.TIME desc) where rownum = 1";
        dr = cmd.ExecuteReader();
        if (dr.HasRows)
        {
            dr.Read();
                if (!dr.IsDBNull(0))
            line.Alarm = (dr.GetFloat(0) > 0 ? true : false);
        }

        cmd.CommandText = "select min(time) from PGMS_CURRENT_INFO where TRANSMISSIONLINE =:lineName and (NAME='实时电流' or NAME='导线温度' or NAME='温度' or NAME='在线状态' or NAME='实时功率' or NAME='总功率' or NAME='热稳限额' or NAME='功率限额')";
        dr = cmd.ExecuteReader();
        if (dr.HasRows)
        {
            dr.Read();
                if (!dr.IsDBNull(0))
            line.Time = dr.GetDateTime(0).ToString();
        }
        dr.Close();
        conn.Close();

        return line;
    }
    List<String> getLineStatisticsTableNameList(DateTime begin,DateTime end)
    {
        List<String> tableNameList = new List<string>();
        DateTime p;
        for (p = begin; p <= end; p = p.AddYears(1))
        {
            tableNameList.Add("PGMS_DAYSTATISTIC_" + p.Year.ToString("D4"));
        }
        if (p.Year == end.Year)//剩下一个月未处理
        {
            tableNameList.Add("PGMS_DAYSTATISTIC_" + p.Year.ToString("D4"));
        }
        return tableNameList;

    }

    /* 
    * 数据统计-杆塔倾斜-历史数据查询 4.1
    * lname:线路名称
    * begin:开始时间
    * end:结束时间
    */
    public DataTable getDTDataStatisticsGTQX(String lname, DateTime begin, DateTime end)
    {
        DataTable metricHistoryDataTable = new DataTable();
        try
        {
            String connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["OracleConnectionString"].ConnectionString;
            OracleConnection conn = new OracleConnection(connectionString);
            OracleCommand cmd = new OracleCommand();
            cmd.Connection = conn;
            conn.Open();
            List<String> tableNameList = getLineStatisticsTableNameList(begin, end);
            metricHistoryDataTable.Columns.Add("线路名称");
            metricHistoryDataTable.Columns.Add("杆塔名称");
            metricHistoryDataTable.Columns.Add("综合倾斜度最大值(%)");
            metricHistoryDataTable.Columns.Add("最大值时间"); //3
            metricHistoryDataTable.Columns.Add("杆塔倾斜告警阀值1(%)");
            metricHistoryDataTable.Columns.Add("杆塔倾斜告警阀值2(%)");
            metricHistoryDataTable.Columns.Add("杆塔倾斜告警阀值3(%)");
            metricHistoryDataTable.Columns.Add("告警次数");
            for (int i = 0; i < tableNameList.Count; i++)
            {
                cmd.CommandText = "select a.transmissionline,a.equipment,a.maxvalue,a.maxtime,b.value,c.value,d.value,(select count(*) from pgms_alarm_history where equipment=a.equipment and act_time between :timeBegin and :timeEnd and (act_description='杆塔轻度倾斜' or act_description='杆塔中度倾斜' or act_description='杆塔重度倾斜')) as alarm_num from " + tableNameList[i] +
                    " a join pgms_current_info b on(a.equipment=b.equipment) join pgms_current_info c on(a.equipment=c.equipment) join pgms_current_info d on(a.equipment=d.equipment) where exists (select * from (select equipment,max(maxvalue) as value from " + tableNameList[i] +
                    " where transmissionline=:lineName and name='杆塔倾斜度' and maxtime between :timeBegin and :timeEnd group by equipment) where equipment=a.equipment and value=a.maxvalue) and a.transmissionline=:lineName and a.name='杆塔倾斜度' and a.maxtime between :timeBegin and :timeEnd and b.name='杆塔倾斜度阀值1' and c.name='杆塔倾斜度阀值2' and d.name='杆塔倾斜度阀值3' order by equipment";

                cmd.Parameters.Add(":lineName", OracleType.VarChar);
                cmd.Parameters[":lineName"].Value = lname;
                cmd.Parameters.Add(":timeBegin", OracleType.Timestamp);
                cmd.Parameters[":timeBegin"].Value = begin;
                cmd.Parameters.Add(":timeEnd", OracleType.Timestamp);
                cmd.Parameters[":timeEnd"].Value = end;

                OracleDataReader dr = cmd.ExecuteReader();

                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        if (!dr.IsDBNull(0) && !dr.IsDBNull(1) && !dr.IsDBNull(2) && !dr.IsDBNull(3) && !dr.IsDBNull(4) && !dr.IsDBNull(5) && !dr.IsDBNull(6) && !dr.IsDBNull(7))
                            metricHistoryDataTable.Rows.Add(new Object[] { dr.GetString(0), dr.GetString(1), dr.GetFloat(2).ToString("f2"), dr.GetDateTime(3), dr.GetFloat(4).ToString("f2"), dr.GetFloat(5).ToString("f2"), dr.GetFloat(6).ToString("f2"), dr.GetInt32(7) });
                    }
                }
            }
            conn.Close();
        }
        catch (OracleException e)
        {
        }
        return metricHistoryDataTable;
    }

    /* 
    * 数据统计-环境气象-历史数据查询 4.2
    * lname:线路名称
    * mname:测量量名
    * begin:开始时间
    * end:结束时间
    */
    public DataTable getDTDataStatisticsHJQX(String lname,String mname, DateTime begin, DateTime end)
    {
        DataTable metricHistoryDataTable = new DataTable();
        try
        {
            String connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["OracleConnectionString"].ConnectionString;
            OracleConnection conn = new OracleConnection(connectionString);
            OracleCommand cmd = new OracleCommand();
            cmd.Connection = conn;
            conn.Open();
            List<String> tableNameList = getLineStatisticsTableNameList(begin, end);
            if (mname.Equals("温度"))
            {
                metricHistoryDataTable.Columns.Add("线路名称");
                metricHistoryDataTable.Columns.Add("杆塔名称");
                metricHistoryDataTable.Columns.Add("温度最大值(℃)");
                metricHistoryDataTable.Columns.Add("最大值时间"); //3
                metricHistoryDataTable.Columns.Add("告警阀值1(℃)");
                metricHistoryDataTable.Columns.Add("告警阀值2(℃)");
                metricHistoryDataTable.Columns.Add("告警阀值3(℃)");
                metricHistoryDataTable.Columns.Add("告警次数");
                for (int i = 0; i < tableNameList.Count; i++)
                {
                    cmd.CommandText = "select a.transmissionline,a.equipment,a.maxvalue,a.maxtime,b.value,c.value,d.value,(select count(*) from pgms_alarm_history where equipment=a.equipment and act_time between :timeBegin and :timeEnd and (act_description='温度黄色告警' or act_description='温度橙色告警' or act_description='温度红色告警')) as alarm_num from " + tableNameList[i] +
                        " a join pgms_current_info b on(a.equipment=b.equipment) join pgms_current_info c on(a.equipment=c.equipment) join pgms_current_info d on(a.equipment=d.equipment) where exists (select * from (select equipment,max(maxvalue) as value from " + tableNameList[i] + " where transmissionline=:lineName and name='温度' and maxtime between :timeBegin and :timeEnd group by equipment) where equipment=a.equipment and value=a.maxvalue) and a.transmissionline=:lineName and a.name='温度' and a.maxtime between :timeBegin and :timeEnd and b.name='温度黄色告警限值' and c.name='温度橙色告警限值' and d.name='温度红色告警限值' order by equipment";
                    cmd.Parameters.Add(":lineName", OracleType.VarChar);
                    cmd.Parameters[":lineName"].Value = lname;
                    cmd.Parameters.Add(":timeBegin", OracleType.Timestamp);
                    cmd.Parameters[":timeBegin"].Value = begin;
                    cmd.Parameters.Add(":timeEnd", OracleType.Timestamp);
                    cmd.Parameters[":timeEnd"].Value = end;

                    OracleDataReader dr = cmd.ExecuteReader();

                    if (dr.HasRows)
                    {
                        while (dr.Read())
                        {
                            if (!dr.IsDBNull(0) && !dr.IsDBNull(1) && !dr.IsDBNull(2) && !dr.IsDBNull(3) && !dr.IsDBNull(4) && !dr.IsDBNull(5) && !dr.IsDBNull(6) && !dr.IsDBNull(7))
                                metricHistoryDataTable.Rows.Add(new Object[] { dr.GetString(0), dr.GetString(1), dr.GetFloat(2).ToString("f2"), dr.GetDateTime(3), dr.GetFloat(4).ToString("f2"), dr.GetFloat(5).ToString("f2"), dr.GetFloat(6).ToString("f2"), dr.GetInt32(7) });
                        }
                    }
                }

            }
            else if (mname.Equals("风速"))
            {
                metricHistoryDataTable.Columns.Add("线路名称");
                metricHistoryDataTable.Columns.Add("杆塔名称");
                metricHistoryDataTable.Columns.Add("风速最大值(m/s)");
                metricHistoryDataTable.Columns.Add("最大值时间"); //3
                metricHistoryDataTable.Columns.Add("告警阀值1(m/s)");
                metricHistoryDataTable.Columns.Add("告警阀值2(m/s)");
                metricHistoryDataTable.Columns.Add("告警阀值3(m/s)");
                metricHistoryDataTable.Columns.Add("告警次数");
                for (int i = 0; i < tableNameList.Count; i++)
                {
                    cmd.CommandText = "select a.transmissionline,a.equipment,a.maxvalue,a.maxtime,b.value,c.value,d.value,(select count(*) from pgms_alarm_history where equipment=a.equipment and act_time between :timeBegin and :timeEnd and (act_description='大风黄色告警' or act_description='大风橙色告警' or act_description='大风红色告警')) as alarm_num from " + tableNameList[i] +
                        " a join pgms_current_info b on(a.equipment=b.equipment) join pgms_current_info c on(a.equipment=c.equipment) join pgms_current_info d on(a.equipment=d.equipment) where exists (select * from (select equipment,max(maxvalue) as value from " + tableNameList[i] + " where transmissionline=:lineName and name='风速' and maxtime between :timeBegin and :timeEnd group by equipment) where equipment=a.equipment and value=a.maxvalue) and a.transmissionline=:lineName and a.name='风速' and a.maxtime between :timeBegin and :timeEnd and b.name='大风黄色告警限值' and c.name='大风橙色告警限值' and d.name='大风红色告警限值' order by equipment";
                    cmd.Parameters.Add(":lineName", OracleType.VarChar);
                    cmd.Parameters[":lineName"].Value = lname;
                    cmd.Parameters.Add(":timeBegin", OracleType.Timestamp);
                    cmd.Parameters[":timeBegin"].Value = begin;
                    cmd.Parameters.Add(":timeEnd", OracleType.Timestamp);
                    cmd.Parameters[":timeEnd"].Value = end;

                    OracleDataReader dr = cmd.ExecuteReader();

                    if (dr.HasRows)
                    {
                        while (dr.Read())
                        {
                            if (!dr.IsDBNull(0) && !dr.IsDBNull(1) && !dr.IsDBNull(2) && !dr.IsDBNull(3) && !dr.IsDBNull(4) && !dr.IsDBNull(5) && !dr.IsDBNull(6) && !dr.IsDBNull(7))
                                metricHistoryDataTable.Rows.Add(new Object[] { dr.GetString(0), dr.GetString(1), dr.GetFloat(2).ToString("f2"), dr.GetDateTime(3), dr.GetFloat(4).ToString("f2"), dr.GetFloat(5).ToString("f2"), dr.GetFloat(6).ToString("f2"), dr.GetInt32(7) });
                        }
                    }
                }

            }
            else if (mname.Equals("雨量"))
            {
                metricHistoryDataTable.Columns.Add("线路名称");
                metricHistoryDataTable.Columns.Add("杆塔名称");
                metricHistoryDataTable.Columns.Add("雨量最大值(mm/h)");
                metricHistoryDataTable.Columns.Add("最大值时间"); //3
                metricHistoryDataTable.Columns.Add("告警阀值1(mm/h)");
                metricHistoryDataTable.Columns.Add("告警阀值2(mm/h)");
                metricHistoryDataTable.Columns.Add("告警阀值3(mm/h)");
                metricHistoryDataTable.Columns.Add("告警次数");
                for (int i = 0; i < tableNameList.Count; i++)
                {
                    cmd.CommandText = "select a.transmissionline,a.equipment,a.maxvalue,a.maxtime,b.value,c.value,d.value,(select count(*) from pgms_alarm_history where equipment=a.equipment and act_time between :timeBegin and :timeEnd and (act_description='降雨黄色告警' or act_description='降雨橙色告警' or act_description='降雨红色告警')) as alarm_num from " + tableNameList[i] +
                        " a join pgms_current_info b on(a.equipment=b.equipment) join pgms_current_info c on(a.equipment=c.equipment) join pgms_current_info d on(a.equipment=d.equipment) where exists (select * from (select equipment,max(maxvalue) as value from " + tableNameList[i] + " where transmissionline=:lineName and name='雨量' and maxtime between :timeBegin and :timeEnd group by equipment) where equipment=a.equipment and value=a.maxvalue) and a.transmissionline=:lineName and a.name='雨量' and a.maxtime between :timeBegin and :timeEnd and b.name='降雨黄色告警限值' and c.name='降雨橙色告警限值' and d.name='降雨红色告警限值' order by equipment";
                    cmd.Parameters.Add(":lineName", OracleType.VarChar);
                    cmd.Parameters[":lineName"].Value = lname;
                    cmd.Parameters.Add(":timeBegin", OracleType.Timestamp);
                    cmd.Parameters[":timeBegin"].Value = begin;
                    cmd.Parameters.Add(":timeEnd", OracleType.Timestamp);
                    cmd.Parameters[":timeEnd"].Value = end;

                    OracleDataReader dr = cmd.ExecuteReader();

                    if (dr.HasRows)
                    {
                        while (dr.Read())
                        {
                            if (!dr.IsDBNull(0) && !dr.IsDBNull(1) && !dr.IsDBNull(2) && !dr.IsDBNull(3) && !dr.IsDBNull(4) && !dr.IsDBNull(5) && !dr.IsDBNull(6) && !dr.IsDBNull(7))
                                metricHistoryDataTable.Rows.Add(new Object[] { dr.GetString(0), dr.GetString(1), dr.GetFloat(2).ToString("f2"), dr.GetDateTime(3), dr.GetFloat(4).ToString("f2"), dr.GetFloat(5).ToString("f2"), dr.GetFloat(6).ToString("f2"), dr.GetInt32(7) });
                        }
                    }
                }

            }
            conn.Close();
        }
        catch (OracleException e)
        {
        }
        return metricHistoryDataTable;
    }


    /* 
    * 数据统计-导线覆冰-历史数据查询 4.2
    * lname:线路名称
    * mname:测量量名
    * begin:开始时间
    * end:结束时间
    */
    public DataTable getDTDataStatisticsDXLB(String lname,DateTime begin, DateTime end)
    {
        DataTable metricHistoryDataTable = new DataTable();
        try
        {
            String connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["OracleConnectionString"].ConnectionString;
            OracleConnection conn = new OracleConnection(connectionString);
            OracleCommand cmd = new OracleCommand();
            cmd.Connection = conn;
            conn.Open();
            List<String> tableNameList = getLineStatisticsTableNameList(begin, end);
            metricHistoryDataTable.Columns.Add("线路名称");
            metricHistoryDataTable.Columns.Add("杆塔名称");
            metricHistoryDataTable.Columns.Add("覆冰厚度最大值(mm)");
            metricHistoryDataTable.Columns.Add("最大值时间"); //3
            metricHistoryDataTable.Columns.Add("告警阀值1(mm)");
            metricHistoryDataTable.Columns.Add("告警阀值2(mm)");
            metricHistoryDataTable.Columns.Add("告警阀值3(mm)");
            metricHistoryDataTable.Columns.Add("告警次数");
            for (int i = 0; i < tableNameList.Count; i++)
            {

                cmd.CommandText = "select a.transmissionline,a.equipment,a.maxvalue,a.maxtime,b.value,c.value,d.value,(select count(*) from pgms_alarm_history where equipment=a.equipment and act_time between :timeBegin and :timeEnd and (act_description='覆冰轻度告警' or act_description='覆冰中度告警' or act_description='覆冰重度告警')) as alarm_num from " + tableNameList[i] +
                    " a join pgms_current_info b on(a.equipment=b.equipment) join pgms_current_info c on(a.equipment=c.equipment) join pgms_current_info d on(a.equipment=d.equipment) where exists (select * from (select equipment,max(maxvalue) as value from " + tableNameList[i] + " where transmissionline=:lineName and name='覆冰厚度' and maxtime between :timeBegin and timeEnd group by equipment) where equipment=a.equipment and value=a.maxvalue) and a.transmissionline=:lineName and a.name='覆冰厚度' and a.maxtime between :timeBegin and timeEnd and b.name='覆冰厚度阀值1' and c.name='覆冰厚度阀值2' and d.name='覆冰厚度阀值3' order by equipment";

                cmd.Parameters.Add(":lineName", OracleType.VarChar);
                cmd.Parameters[":lineName"].Value = lname;
                cmd.Parameters.Add(":timeBegin", OracleType.Timestamp);
                cmd.Parameters[":timeBegin"].Value = begin;
                cmd.Parameters.Add(":timeEnd", OracleType.Timestamp);
                cmd.Parameters[":timeEnd"].Value = end;

                OracleDataReader dr = cmd.ExecuteReader();


                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        if (!dr.IsDBNull(0) && !dr.IsDBNull(1) && !dr.IsDBNull(2) && !dr.IsDBNull(3) && !dr.IsDBNull(4) && !dr.IsDBNull(5) && !dr.IsDBNull(6) && !dr.IsDBNull(7))
                            metricHistoryDataTable.Rows.Add(new Object[] { dr.GetString(0), dr.GetString(1), dr.GetFloat(2).ToString("f2"), dr.GetDateTime(3), dr.GetFloat(4).ToString("f2"), dr.GetFloat(5).ToString("f2"), dr.GetFloat(6).ToString("f2"), dr.GetInt32(7) });
                    }
                }
            }
            conn.Close();
        }
        catch (OracleException e)
        {
        }
        return metricHistoryDataTable;
    }

    /* 
   * 数据统计-动态增容-历史数据查询 4.2
   * lname:线路名称
   * mname:测量量名
   * begin:开始时间
   * end:结束时间
   */
    public DataTable getDTDataStatisticsDTZR(String lname, String mname, DateTime begin, DateTime end)
    {
        DataTable metricHistoryDataTable = new DataTable();
        try
        {
            String connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["OracleConnectionString"].ConnectionString;
            OracleConnection conn = new OracleConnection(connectionString);
            OracleCommand cmd = new OracleCommand();
            cmd.Connection = conn;
            conn.Open();
            List<String> tableNameList = getLineStatisticsTableNameList(begin, end);
            if (mname.Equals("导线温度最大值"))
            {
                metricHistoryDataTable.Columns.Add("线路名称");
                metricHistoryDataTable.Columns.Add("杆塔名称");
                metricHistoryDataTable.Columns.Add("导线温度最大值(℃)");
                metricHistoryDataTable.Columns.Add("最大值时间"); //3
                for (int i = 0; i < tableNameList.Count; i++)
                {
                    cmd.CommandText = "select transmissionline,equipment,maxvalue, maxtime from " + tableNameList[i] +
                                " where exists (select * from (select equipment,max(maxvalue) as value from " + tableNameList[i] +
                                " where transmissionline=:lineName and name='导线温度' and maxtime between :timeBegin and :timeEnd group by equipment) where equipment = " + tableNameList[i] + ".equipment and value= " + tableNameList[i] + ".maxvalue) and transmissionline=:lineName and name='导线温度' and maxtime between :timeBegin and :timeEnd order by equipment";


                    cmd.Parameters.Add(":lineName", OracleType.VarChar);
                    cmd.Parameters[":lineName"].Value = lname;
                    cmd.Parameters.Add(":timeBegin", OracleType.Timestamp);
                    cmd.Parameters[":timeBegin"].Value = begin;
                    cmd.Parameters.Add(":timeEnd", OracleType.Timestamp);
                    cmd.Parameters[":timeEnd"].Value = end;

                    OracleDataReader dr = cmd.ExecuteReader();
                    if (dr.HasRows)
                    {
                        while (dr.Read())
                        {
                            if (!dr.IsDBNull(0) && !dr.IsDBNull(1) && !dr.IsDBNull(2) && !dr.IsDBNull(3))
                                metricHistoryDataTable.Rows.Add(new Object[] { dr.GetString(0), dr.GetString(1), dr.GetFloat(2).ToString("f2"), dr.GetDateTime(3) });
                        }
                    }
                }

            }
            else if (mname.Equals("导线温度最小值"))
            {
                metricHistoryDataTable.Columns.Add("线路名称");
                metricHistoryDataTable.Columns.Add("杆塔名称");
                metricHistoryDataTable.Columns.Add("导线温度最小值(℃)");
                metricHistoryDataTable.Columns.Add("最小值时间"); //3
                for (int i = 0; i < tableNameList.Count; i++)
                {
                    cmd.CommandText = "select transmissionline,equipment,minvalue, mintime from " + tableNameList[i] +
                                " where exists (select * from (select equipment,min(minvalue) as value from " + tableNameList[i] +
                                " where transmissionline=:lineName and name='导线温度' and mintime between :timeBegin and :timeEnd group by equipment) where equipment = " + tableNameList[i] + ".equipment and value= " + tableNameList[i] + ".minvalue) and transmissionline=:lineName and name='导线温度' and mintime between :timeBegin and :timeEnd order by equipment";


                    cmd.Parameters.Add(":lineName", OracleType.VarChar);
                    cmd.Parameters[":lineName"].Value = lname;
                    cmd.Parameters.Add(":timeBegin", OracleType.Timestamp);
                    cmd.Parameters[":timeBegin"].Value = begin;
                    cmd.Parameters.Add(":timeEnd", OracleType.Timestamp);
                    cmd.Parameters[":timeEnd"].Value = end;

                    OracleDataReader dr = cmd.ExecuteReader();
                    if (dr.HasRows)
                    {
                        while (dr.Read())
                        {
                            if (!dr.IsDBNull(0) && !dr.IsDBNull(1) && !dr.IsDBNull(2) && !dr.IsDBNull(3))
                                metricHistoryDataTable.Rows.Add(new Object[] { dr.GetString(0), dr.GetString(1), dr.GetFloat(2).ToString("f2"), dr.GetDateTime(3) });
                        }
                    }
                }
            }
            else if (mname.Equals("限额电流最大值"))
            {
                metricHistoryDataTable.Columns.Add("线路名称");
                metricHistoryDataTable.Columns.Add("杆塔名称");
                metricHistoryDataTable.Columns.Add("限额电流最大值(A)");
                metricHistoryDataTable.Columns.Add("最大值时间"); //3
                for (int i = 0; i < tableNameList.Count; i++)
                {
                    cmd.CommandText = "select transmissionline,equipment,maxvalue, maxtime from " + tableNameList[i] +
                                " where exists (select * from (select equipment,max(maxvalue) as value from " + tableNameList[i] +
                                " where transmissionline=:lineName and name='最大允许电流' and maxtime between :timeBegin and :timeEnd group by equipment) where equipment = " + tableNameList[i] + ".equipment and value= " + tableNameList[i] + ".maxvalue) and transmissionline=:lineName and name='最大允许电流' and maxtime between :timeBegin and :timeEnd order by equipment";


                    cmd.Parameters.Add(":lineName", OracleType.VarChar);
                    cmd.Parameters[":lineName"].Value = lname;
                    cmd.Parameters.Add(":timeBegin", OracleType.Timestamp);
                    cmd.Parameters[":timeBegin"].Value = begin;
                    cmd.Parameters.Add(":timeEnd", OracleType.Timestamp);
                    cmd.Parameters[":timeEnd"].Value = end;

                    OracleDataReader dr = cmd.ExecuteReader();
                    if (dr.HasRows)
                    {
                        while (dr.Read())
                        {
                            if (!dr.IsDBNull(0) && !dr.IsDBNull(1) && !dr.IsDBNull(2) && !dr.IsDBNull(3))
                                metricHistoryDataTable.Rows.Add(new Object[] { dr.GetString(0), dr.GetString(1), dr.GetFloat(2).ToString("f2"), dr.GetDateTime(3) });
                        }
                    }
                }
            }
            else if (mname.Equals("限额电流最小值"))
            {
                metricHistoryDataTable.Columns.Add("线路名称");
                metricHistoryDataTable.Columns.Add("杆塔名称");
                metricHistoryDataTable.Columns.Add("限额电流最小值(A)");
                metricHistoryDataTable.Columns.Add("最小值时间"); //3
                for (int i = 0; i < tableNameList.Count; i++)
                {
                    cmd.CommandText = "select transmissionline,equipment,minvalue, mintime from " + tableNameList[i] +
                                " where exists (select * from (select equipment,min(minvalue) as value from " + tableNameList[i] +
                                " where transmissionline=:lineName and name='最大允许电流' and mintime between :timeBegin and :timeEnd group by equipment) where equipment = " + tableNameList[i] + ".equipment and value= " + tableNameList[i] + ".minvalue) and transmissionline=:lineName and name='最大允许电流' and mintime between :timeBegin and :timeEnd order by equipment";


                    cmd.Parameters.Add(":lineName", OracleType.VarChar);
                    cmd.Parameters[":lineName"].Value = lname;
                    cmd.Parameters.Add(":timeBegin", OracleType.Timestamp);
                    cmd.Parameters[":timeBegin"].Value = begin;
                    cmd.Parameters.Add(":timeEnd", OracleType.Timestamp);
                    cmd.Parameters[":timeEnd"].Value = end;

                    OracleDataReader dr = cmd.ExecuteReader();
                    if (dr.HasRows)
                    {
                        while (dr.Read())
                        {
                            if (!dr.IsDBNull(0) && !dr.IsDBNull(1) && !dr.IsDBNull(2) && !dr.IsDBNull(3))
                                metricHistoryDataTable.Rows.Add(new Object[] { dr.GetString(0), dr.GetString(1), dr.GetFloat(2).ToString("f2"), dr.GetDateTime(3) });
                        }
                    }
                }
            }
            else if (mname.Equals("热稳限额最大值"))
            {
                metricHistoryDataTable.Columns.Add("线路名称");
                metricHistoryDataTable.Columns.Add("杆塔名称");
                metricHistoryDataTable.Columns.Add("热稳限额最大值(MW)");
                metricHistoryDataTable.Columns.Add("最大值时间"); //3
                for (int i = 0; i < tableNameList.Count; i++)
                {
                    cmd.CommandText = "select transmissionline,equipment,maxvalue, maxtime from " + tableNameList[i] +
                                " where exists (select * from (select equipment,max(maxvalue) as value from " + tableNameList[i] +
                                " where transmissionline=:lineName and name='热稳限额' and maxtime between :timeBegin and :timeEnd group by equipment) where equipment = " + tableNameList[i] + ".equipment and value= " + tableNameList[i] + ".maxvalue) and transmissionline=:lineName and name='热稳限额' and maxtime between :timeBegin and :timeEnd order by equipment";


                    cmd.Parameters.Add(":lineName", OracleType.VarChar);
                    cmd.Parameters[":lineName"].Value = lname;
                    cmd.Parameters.Add(":timeBegin", OracleType.Timestamp);
                    cmd.Parameters[":timeBegin"].Value = begin;
                    cmd.Parameters.Add(":timeEnd", OracleType.Timestamp);
                    cmd.Parameters[":timeEnd"].Value = end;

                    OracleDataReader dr = cmd.ExecuteReader();
                    if (dr.HasRows)
                    {
                        while (dr.Read())
                        {
                            if (!dr.IsDBNull(0) && !dr.IsDBNull(1) && !dr.IsDBNull(2) && !dr.IsDBNull(3))
                                metricHistoryDataTable.Rows.Add(new Object[] { dr.GetString(0), dr.GetString(1), dr.GetFloat(2).ToString("f2"), dr.GetDateTime(3) });
                        }
                    }
                }

            }
            else if (mname.Equals("热稳限额最小值"))
            {
                metricHistoryDataTable.Columns.Add("线路名称");
                metricHistoryDataTable.Columns.Add("杆塔名称");
                metricHistoryDataTable.Columns.Add("热稳限额最小值(MW)");
                metricHistoryDataTable.Columns.Add("最小值时间"); //3
                for (int i = 0; i < tableNameList.Count; i++)
                {
                    cmd.CommandText = "select transmissionline,equipment,minvalue, mintime from " + tableNameList[i] +
                                " where exists (select * from (select equipment,min(minvalue) as value from " + tableNameList[i] +
                                " where transmissionline=:lineName and name='热稳限额' and mintime between :timeBegin and :timeEnd group by equipment) where equipment = " + tableNameList[i] + ".equipment and value= " + tableNameList[i] + ".minvalue) and transmissionline=:lineName and name='热稳限额' and mintime between :timeBegin and :timeEnd order by equipment";


                    cmd.Parameters.Add(":lineName", OracleType.VarChar);
                    cmd.Parameters[":lineName"].Value = lname;
                    cmd.Parameters.Add(":timeBegin", OracleType.Timestamp);
                    cmd.Parameters[":timeBegin"].Value = begin;
                    cmd.Parameters.Add(":timeEnd", OracleType.Timestamp);
                    cmd.Parameters[":timeEnd"].Value = end;

                    OracleDataReader dr = cmd.ExecuteReader();
                    if (dr.HasRows)
                    {
                        while (dr.Read())
                        {
                            if (!dr.IsDBNull(0) && !dr.IsDBNull(1) && !dr.IsDBNull(2) && !dr.IsDBNull(3))
                                metricHistoryDataTable.Rows.Add(new Object[] { dr.GetString(0), dr.GetString(1), dr.GetFloat(2).ToString("f2"), dr.GetDateTime(3) });
                        }
                    }
                }
            }
            conn.Close();
        }
        catch (OracleException e)
        {
        }
        return metricHistoryDataTable;
    }

    /* 
    * 数据统计-危险点告警-历史数据查询 4.2
    * lname:线路名称
    * begin:开始时间
    * end:结束时间
    */
    public DataTable getDTDataStatisticsWXDGJ(String lname,DateTime begin, DateTime end)
    {
        DataTable metricHistoryDataTable = new DataTable();
        String connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["OracleConnectionString"].ConnectionString;
        OracleConnection conn = new OracleConnection(connectionString);
        OracleCommand cmd = new OracleCommand();
        cmd.Connection = conn;
        conn.Open();
        metricHistoryDataTable.Columns.Add("线路名称");
        metricHistoryDataTable.Columns.Add("杆塔名称");
        metricHistoryDataTable.Columns.Add("报警时间");
        metricHistoryDataTable.Columns.Add("报警原因"); //3

        cmd.CommandText = "select transmissionline,equipment,act_time,object_description from pgms_alarm_history where (name='红外报警1' or name='红外报警2') and transmissionline=:lineName and (act_level=2 or act_level=3) and act_time between :timeBegin and :timeEnd";

        cmd.Parameters.Add(":lineName", OracleType.VarChar);
        cmd.Parameters[":lineName"].Value = lname;
        cmd.Parameters.Add(":timeBegin", OracleType.Timestamp);
        cmd.Parameters[":timeBegin"].Value = begin;
        cmd.Parameters.Add(":timeEnd", OracleType.Timestamp);
        cmd.Parameters[":timeEnd"].Value = end;

        OracleDataReader dr = cmd.ExecuteReader();

        if (dr.HasRows)
        {
            while (dr.Read())
            {
                if (!dr.IsDBNull(0) && !dr.IsDBNull(1) && !dr.IsDBNull(2) && !dr.IsDBNull(3))
                    metricHistoryDataTable.Rows.Add(new Object[] { dr.GetString(0), dr.GetString(1), dr.GetDateTime(2), dr.GetString(3) });
            }
        }
      
        conn.Close();
        return metricHistoryDataTable;
    }


    public DataTable getGJBReport(String lname, DateTime begin, DateTime end)
    {
        DataTable metricHistoryDataTable = new DataTable();
        String connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["OracleConnectionString"].ConnectionString;
        OracleConnection conn = new OracleConnection(connectionString);
        OracleCommand cmd = new OracleCommand();
        cmd.Connection = conn;
        metricHistoryDataTable.Columns.Add("线路名称");
        metricHistoryDataTable.Columns.Add("塔杆名称");
        metricHistoryDataTable.Columns.Add("报警时间");
        metricHistoryDataTable.Columns.Add("报警原因");
        cmd.CommandText = "select transmissionline,equipment,act_time,object_description from pgms_alarm_history where (name='红外报警1' or name='红外报警2') and transmissionline=:lineName and (act_level=2 or act_level=3) and act_time between :timeBegin and :timeEnd";
        cmd.Parameters.Add(":lineName", OracleType.VarChar);
        cmd.Parameters[":lineName"].Value = lname;
        cmd.Parameters.Add(":timeBegin", OracleType.Timestamp);
        cmd.Parameters[":timeBegin"].Value = begin;
        cmd.Parameters.Add(":timeEnd", OracleType.Timestamp);
        cmd.Parameters[":timeEnd"].Value = end;
        conn.Open();
        OracleDataReader dr;

        dr = cmd.ExecuteReader();
        if (dr.HasRows)
        {
            while (dr.Read())
            {
                if (!dr.IsDBNull(0) && !dr.IsDBNull(1) && !dr.IsDBNull(2) && !dr.IsDBNull(3))
                    metricHistoryDataTable.Rows.Add(new object[] { dr.GetString(0), dr.GetString(1), dr.GetDateTime(2), dr.GetString(3) });
            }
        }
        return metricHistoryDataTable;
    }

    public DataTable getMonthReport(String lname, DateTime begin, DateTime end)
    {
        DataTable metricHistoryDataTable = new DataTable();
        String connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["OracleConnectionString"].ConnectionString;
        OracleConnection conn = new OracleConnection(connectionString);
        OracleCommand cmd = new OracleCommand();
        cmd.Connection = conn;
        metricHistoryDataTable.Columns.Add("线路名称");
        metricHistoryDataTable.Columns.Add("时间");
        metricHistoryDataTable.Columns.Add("温度(°C)");
        metricHistoryDataTable.Columns.Add("湿度(%RH)");
        metricHistoryDataTable.Columns.Add("风速(m/s)");
        metricHistoryDataTable.Columns.Add("风向(°)");
        metricHistoryDataTable.Columns.Add("气压(kPa)");
        metricHistoryDataTable.Columns.Add("雨量(mm/h)");
        metricHistoryDataTable.Columns.Add("日照强度(w/m^2)");
        metricHistoryDataTable.Columns.Add("导线倾斜角(°)");
        metricHistoryDataTable.Columns.Add("导线拉力(N)");
        metricHistoryDataTable.Columns.Add("导线弧垂(m)");
        metricHistoryDataTable.Columns.Add("导线覆冰厚度(mm)");
        metricHistoryDataTable.Columns.Add("导线温度(°C)");
        metricHistoryDataTable.Columns.Add("实时电流(A)");
        metricHistoryDataTable.Columns.Add("限额电流(A)");
        metricHistoryDataTable.Columns.Add("实时功率(MW)");
        metricHistoryDataTable.Columns.Add("热稳限额(MW)");
        //metricHistoryDataTable.Columns.Add("顺线倾斜角");
        //metricHistoryDataTable.Columns.Add("横向倾斜角");
        //metricHistoryDataTable.Columns.Add("顺线倾斜度");
        //metricHistoryDataTable.Columns.Add("横向倾斜度");
        metricHistoryDataTable.Columns.Add("综合倾斜度");
        cmd.CommandText = "select transmissionline ,to_char(time,'yyyy-mm-dd'),max(temperature),max(humidity),max(windspeed),max(winddirection),max(atome_pressure),max(rainfall),max(sunlight),max(angleof_line1),max(forceof_line),max(sagof_line),max(thicknessof_ice),max(temperatureof_line),max(current_realtime),max(max_current),max(limitof_power),max(threholdof_heat),max(gradient_tower) from pgms_tower6_2011 where transmissionline=:lineName and time between :timeBegin and :timeEnd group by to_char(time,'yyyy-mm-dd'), transmissionline";

        cmd.Parameters.Add(":lineName", OracleType.VarChar);
        cmd.Parameters[":lineName"].Value = lname;
        cmd.Parameters.Add(":timeBegin", OracleType.Timestamp);
        cmd.Parameters[":timeBegin"].Value = begin;
        cmd.Parameters.Add(":timeEnd", OracleType.Timestamp);
        cmd.Parameters[":timeEnd"].Value = end;
        conn.Open();
        OracleDataReader dr;

        dr = cmd.ExecuteReader();
        if (dr.HasRows)
        {
            while (dr.Read())
            {
                if (!dr.IsDBNull(0) && !dr.IsDBNull(1) && !dr.IsDBNull(2) && !dr.IsDBNull(3) && !dr.IsDBNull(4) && !dr.IsDBNull(5) && !dr.IsDBNull(6) && !dr.IsDBNull(7) && !dr.IsDBNull(8) && !dr.IsDBNull(9) && !dr.IsDBNull(10) && !dr.IsDBNull(11) && !dr.IsDBNull(12) && !dr.IsDBNull(13) && !dr.IsDBNull(14) && !dr.IsDBNull(15) && !dr.IsDBNull(16) && !dr.IsDBNull(17) && !dr.IsDBNull(18))
                    metricHistoryDataTable.Rows.Add(new object[] { dr.GetString(0), dr.GetString(1), dr.GetFloat(2).ToString("f2"), dr.GetFloat(3).ToString("f2"), dr.GetFloat(4).ToString("f2"), dr.GetFloat(5).ToString("f2"), dr.GetFloat(6).ToString("f2"), dr.GetFloat(7).ToString("f2"), dr.GetFloat(8).ToString("f2"), dr.GetFloat(9).ToString("f2"), dr.GetFloat(10).ToString("f2"), dr.GetFloat(11).ToString("f2"), dr.GetFloat(12).ToString("f2"), dr.GetFloat(13).ToString("f2"), dr.GetFloat(14).ToString("f2"), dr.GetFloat(15).ToString("f2"), dr.GetFloat(16).ToString("f2"), dr.GetFloat(17).ToString("f2"), dr.GetFloat(18).ToString("f2") });
            }
        }
        return metricHistoryDataTable;
    }
    public DataTable getYearReport(String lname, DateTime begin, DateTime end)
    {
        DataTable metricHistoryDataTable = new DataTable();
        String connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["OracleConnectionString"].ConnectionString;
        OracleConnection conn = new OracleConnection(connectionString);
        OracleCommand cmd = new OracleCommand();
        cmd.Connection = conn;
        metricHistoryDataTable.Columns.Add("线路名称");
        metricHistoryDataTable.Columns.Add("时间");
        metricHistoryDataTable.Columns.Add("温度(°C)");
        metricHistoryDataTable.Columns.Add("湿度(%RH)");
        metricHistoryDataTable.Columns.Add("风速(m/s)");
        metricHistoryDataTable.Columns.Add("风向(°)");
        metricHistoryDataTable.Columns.Add("气压(kPa)");
        metricHistoryDataTable.Columns.Add("雨量(mm/h)");
        metricHistoryDataTable.Columns.Add("日照强度(w/m^2)");
        metricHistoryDataTable.Columns.Add("导线倾斜角(°)");
        metricHistoryDataTable.Columns.Add("导线拉力(N)");
        metricHistoryDataTable.Columns.Add("导线弧垂(m)");
        metricHistoryDataTable.Columns.Add("导线覆冰厚度(mm)");
        metricHistoryDataTable.Columns.Add("导线温度(°C)");
        metricHistoryDataTable.Columns.Add("实时电流(A)");
        metricHistoryDataTable.Columns.Add("限额电流(A)");
        metricHistoryDataTable.Columns.Add("实时功率(MW)");
        metricHistoryDataTable.Columns.Add("热稳限额(MW)");
        //metricHistoryDataTable.Columns.Add("顺线倾斜角");
        //metricHistoryDataTable.Columns.Add("横向倾斜角");
        //metricHistoryDataTable.Columns.Add("顺线倾斜度");
        //metricHistoryDataTable.Columns.Add("横向倾斜度");
        metricHistoryDataTable.Columns.Add("综合倾斜度");

        cmd.CommandText = "select transmissionline ,to_char(time,'yyyy-mm'),max(temperature),max(humidity),max(windspeed),max(winddirection),max(atome_pressure),max(rainfall),max(sunlight),max(angleof_line1),max(forceof_line),max(sagof_line),max(thicknessof_ice),max(temperatureof_line),max(current_realtime),max(max_current),max(limitof_power),max(threholdof_heat),max(gradient_tower) from pgms_tower6_2011 where transmissionline=:lineName and time between :timeBegin and :timeEnd group by to_char(time,'yyyy-mm'), transmissionline";

        cmd.Parameters.Add(":lineName", OracleType.VarChar);
        cmd.Parameters[":lineName"].Value = lname;
        cmd.Parameters.Add(":timeBegin", OracleType.Timestamp);
        cmd.Parameters[":timeBegin"].Value = begin;
        cmd.Parameters.Add(":timeEnd", OracleType.Timestamp);
        cmd.Parameters[":timeEnd"].Value = end;
        conn.Open();
        OracleDataReader dr;

        dr = cmd.ExecuteReader();
        if (dr.HasRows)
        {
            while (dr.Read())
            {
                if (!dr.IsDBNull(0) && !dr.IsDBNull(1) && !dr.IsDBNull(2) && !dr.IsDBNull(3) && !dr.IsDBNull(4) && !dr.IsDBNull(5) && !dr.IsDBNull(6) && !dr.IsDBNull(7) && !dr.IsDBNull(8) && !dr.IsDBNull(9) && !dr.IsDBNull(10) && !dr.IsDBNull(11) && !dr.IsDBNull(12) && !dr.IsDBNull(13) && !dr.IsDBNull(14) && !dr.IsDBNull(15) && !dr.IsDBNull(16) && !dr.IsDBNull(17) && !dr.IsDBNull(18))
                    metricHistoryDataTable.Rows.Add(new object[] { dr.GetString(0), dr.GetString(1), dr.GetFloat(2).ToString("f2"), dr.GetFloat(3).ToString("f2"), dr.GetFloat(4).ToString("f2"), dr.GetFloat(5).ToString("f2"), dr.GetFloat(6).ToString("f2"), dr.GetFloat(7).ToString("f2"), dr.GetFloat(8).ToString("f2"), dr.GetFloat(9).ToString("f2"), dr.GetFloat(10).ToString("f2"), dr.GetFloat(11).ToString("f2"), dr.GetFloat(12).ToString("f2"), dr.GetFloat(13).ToString("f2"), dr.GetFloat(14).ToString("f2"), dr.GetFloat(15).ToString("f2"), dr.GetFloat(16).ToString("f2"), dr.GetFloat(17).ToString("f2"), dr.GetFloat(18).ToString("f2") });
            }
        }
        return metricHistoryDataTable;
    }
    public DataTable getDayReport(String lname, DateTime begin, DateTime end)
    {
        DataTable metricHistoryDataTable = new DataTable();
        try
        {
            String connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["OracleConnectionString"].ConnectionString;
            OracleConnection conn = new OracleConnection(connectionString);
            OracleCommand cmd = new OracleCommand();
            cmd.Connection = conn;
            conn.Open();
            // List<String> tableNameList = getTowerHistoryTableNameList(lname, tname, begin, end);
            metricHistoryDataTable.Columns.Add("线路名称");
            metricHistoryDataTable.Columns.Add("时间");
            metricHistoryDataTable.Columns.Add("温度(°C)");
            metricHistoryDataTable.Columns.Add("湿度(%RH)");
            metricHistoryDataTable.Columns.Add("风速(m/s)");
            metricHistoryDataTable.Columns.Add("风向(°)");
            metricHistoryDataTable.Columns.Add("气压(kPa)");
            metricHistoryDataTable.Columns.Add("雨量(mm/h)");
            metricHistoryDataTable.Columns.Add("日照强度(w/m^2)");
            metricHistoryDataTable.Columns.Add("导线倾斜角(°)");
            metricHistoryDataTable.Columns.Add("导线拉力(N)");
            metricHistoryDataTable.Columns.Add("导线弧垂(m)");
            metricHistoryDataTable.Columns.Add("导线覆冰厚度(mm)");
            metricHistoryDataTable.Columns.Add("导线温度(°C)");
            metricHistoryDataTable.Columns.Add("实时电流(A)");
            metricHistoryDataTable.Columns.Add("限额电流(A)");
            metricHistoryDataTable.Columns.Add("实时功率(MW)");
            metricHistoryDataTable.Columns.Add("热稳限额(MW)");
            //metricHistoryDataTable.Columns.Add("顺线倾斜角");
            //metricHistoryDataTable.Columns.Add("横向倾斜角");
            //metricHistoryDataTable.Columns.Add("顺线倾斜度");
            //metricHistoryDataTable.Columns.Add("横向倾斜度");
            metricHistoryDataTable.Columns.Add("综合倾斜度");
            cmd.CommandText = @"select transmissionline,to_char(time,'yyyy-mm-dd hh24'),max(temperature),max(humidity),max(windspeed),max(winddirection),max(atome_pressure),                                    max(rainfall),max(sunlight),max(angleof_line1),                                    max(forceof_line),max(sagof_line),max(thicknessof_ice),max(temperatureof_line),max(current_realtime),max(max_current),max(limitof_power),                                    max(threholdof_heat),max(gradient_tower)                                     from pgms_tower6_2011                                    where transmissionline=:lineName and time between :timeBegin and :timeEnd                                    group by to_char(time,'yyyy-mm-dd hh24'),transmissionline";
            //cmd.Parameters.Add(":YearDay", OracleType.VarChar);
            //cmd.Parameters[":YearDay"].Value = begin.ToString("yyyyMM");
            cmd.Parameters.Add(":lineName", OracleType.VarChar);
            cmd.Parameters[":lineName"].Value = lname;
            cmd.Parameters.Add(":timeBegin", OracleType.Timestamp);
            cmd.Parameters[":timeBegin"].Value = begin;
            cmd.Parameters.Add(":timeEnd", OracleType.Timestamp);
            cmd.Parameters[":timeEnd"].Value = end;

            OracleDataReader dr = cmd.ExecuteReader();
            if (dr.HasRows)
            {
                while (dr.Read())
                {
                    if (!dr.IsDBNull(0) && !dr.IsDBNull(1) && !dr.IsDBNull(2) && !dr.IsDBNull(3) && !dr.IsDBNull(4) && !dr.IsDBNull(5) && !dr.IsDBNull(6) && !dr.IsDBNull(7) && !dr.IsDBNull(8) && !dr.IsDBNull(9) && !dr.IsDBNull(10) && !dr.IsDBNull(11) && !dr.IsDBNull(12) && !dr.IsDBNull(13) && !dr.IsDBNull(14) && !dr.IsDBNull(15) && !dr.IsDBNull(16) && !dr.IsDBNull(17) && !dr.IsDBNull(18))
                        metricHistoryDataTable.Rows.Add(new Object[] { dr.GetString(0), dr.GetString(1), dr.GetFloat(2).ToString("f2"), dr.GetFloat(3).ToString("f2"), dr.GetFloat(4).ToString("f2"), dr.GetFloat(5).ToString("f2"), dr.GetFloat(6).ToString("f2"), dr.GetFloat(7).ToString("f2"), dr.GetFloat(8).ToString("f2"), dr.GetFloat(9).ToString("f2"), dr.GetFloat(10).ToString("f2"), dr.GetFloat(11).ToString("f2"), dr.GetFloat(12).ToString("f2"), dr.GetFloat(13).ToString("f2"), dr.GetFloat(14).ToString("f2"), dr.GetFloat(15).ToString("f2"), dr.GetFloat(16).ToString("f2"), dr.GetFloat(17).ToString("f2"), dr.GetFloat(18).ToString("f2") });
                }
            }
            conn.Close();
        }
        catch (OracleException e)
        {

        }
        return metricHistoryDataTable;
    }

    public static LineDAOs getInstance() {
        if (instance == null)
            instance = new LineDAOs();
        return instance;
    }

}
